package com.epam.text_elements;

import java.util.ArrayList;
import java.util.List;

import com.epam.matchers.SentenceSplitter;

public class Paragraph {
	private List<Sentence> body=new ArrayList<Sentence>();
	private int numOfSentences;
	
	public Paragraph(String line) {
		SentenceSplitter sentenceSplitter = new SentenceSplitter();
		body=sentenceSplitter.getListOfSentences(
				line.replaceAll("\\p{Blank}{2,}", " "));
		numOfSentences=body.size();
	}
	
	public List<Sentence> getAllSentences() {
		return body;
	}
	
	public int getNumOfSentences() {
		return numOfSentences;
	}
	
	public Sentence getFirstSentence() {
		return body.get(0);
	}
	
	public String toString() {
		String res="";
		int paragraphSize=body.size();
		//if not a blank line
		if (body.get(0).getNumOfWords()!=0) {
			//all sentences but the last one (space between)
			for (int i=0; i<paragraphSize-1; i++) {
				res+=body.get(i).toString()+" ";
			}
			//the last sentence (no space at the end)
			res+=body.get(paragraphSize-1);
		}
		return res;
	}
}
